<?php
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
class Validator
{
    public function validate(\Closure $closure): void
    {
        $closure();
    }
}

class Test
{
    public function testMethod(): void
    {
        echo "test" . PHP_EOL;
    }
}

class Example
{
    /**
     * @var Validator
     */
    private $validator;
    /**
     * @var Test
     */
    private $test;
    public function __construct()
    {
        $this->validator = new Validator;
        $this->test = new Test;
    }
    public function main(): void
    {
        $this->validator->validate(
            function () {
                $this->test-> // test1
            },
        );
        $func = function () {
            $this->test->testMethod(); // test2
        };
        $func();
        // PHP 7.4 Arrow Function
        $func2 = fn() => $this->test->testMethod(); //test3
        $func2();
    }

}

$example = new Example();
$example->main();
